package com.ssm.rar;

import net.sf.sevenzipjbinding.IInArchive;
import net.sf.sevenzipjbinding.SevenZip;
import net.sf.sevenzipjbinding.impl.RandomAccessFileInStream;

import java.io.File;
import java.io.RandomAccessFile;

public class RaRTest {

    public static void main(String[] args) throws Exception {
        uncompressAllFile(new File("/Users/zhengshaohong/Downloads/mysql面试题文档.rar"), "/Users/zhengshaohong/Downloads/");
    }


    public static void uncompressAllFile(File newFile, String targetFilePath) throws Exception {
        RandomAccessFile randomAccessFile = null;
        IInArchive inArchive = null;
        // 第一个参数是需要解压的压缩包路径，第二个参数参考JdkAPI文档的RandomAccessFile
        randomAccessFile = new RandomAccessFile(newFile.getPath(), "r");
        inArchive = SevenZip.openInArchive(null, new RandomAccessFileInStream(randomAccessFile));
        int[] in = new int[inArchive.getNumberOfItems()];
        for (int i = 0; i < in.length; i++) {
            in[i] = i;
        }
//        inArchive.extract(in, true, new ExtractZipFileCallback(inArchive, targetFilePath));
        //使用回调函数
        inArchive.extract(in, false, new ExtractCallback(inArchive,targetFilePath));
        System.out.println("=======================");
    }

}
